// ----------------------------------
// RSDK Project: Sonic 1/Sonic 2
// Script Description: V Platform Object
// Script Author: Christian Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

//-------Aliases-------//
private alias 49 : TYPE_VPLATFORM

// Function declarations
reserve function VPlatform_DebugDraw
reserve function VPlatform_DebugSpawn

// Static Values

// Tables

function VPlatform_DebugDraw
	DrawSprite(0)
end function


function VPlatform_DebugSpawn
	CreateTempObject(TypeName[V Platform], 0, object.xpos, object.ypos)
	object[tempObjectPos].value0 = object.ypos
	object[tempObjectPos].propertyValue = object.direction
end function


event ObjectMain
	temp7 = object.ypos
	GetTableValue(temp0, 12, StageSetup_table9)
	if object.propertyValue == 1
		FlipSign(temp0)
		temp0 += 0x4000
	else
		temp0 -= 0x4000
	end if
	temp0 <<= 8
	object.ypos = object.value0
	object.ypos -= temp0
	temp1 = object.ypos
	temp7 &= -0x10000
	object.value1 = object.ypos
	object.value1 &= -0x10000
	object.value1 -= temp7
	object.ypos = temp7
	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		CheckEqual(object[currentPlayer].state, PlayerObject_HandleMonikaTeleport)
		temp7 = checkResult
		CheckLower(object[0].value1, 20)
		temp7 &= checkResult
		if temp7 == 0		
			BoxCollisionTest(C_PLATFORM, object.entityPos, -32, -8, 32, 12, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
			if checkResult == 1
				object[currentPlayer].ypos += object.value1
			end if
		end if
	next
	object.ypos = temp1
end event


event ObjectDraw
	DrawSprite(0)
end event


event ObjectStartup
	LoadSpriteSheet("GHZ/Objects.gif")
	SpriteFrame(-32, -14, 64, 32, 50, 18)
	foreach (TypeName[V Platform], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].value0 = object[arrayPos0].ypos
	next
	SetTableValue(TypeName[V Platform], DebugMode_ObjCount, DebugMode_TypesTable)
	SetTableValue(VPlatform_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
	SetTableValue(VPlatform_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
	DebugMode_ObjCount++
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
end event
